<?php
namespace app\home\controller;
use think\Db;
use think\Controller;
use org\util\AjaxPage;
class Read extends Controller{
    function index(){
        $id=input('get.id');
        $data=Db::name('article')->where('id',$id)->find();
        $category_list=Db::name('category')->select();
        $this->assign('category_list',$category_list);
        $this->assign('article',$data);
        //----公共部分使用start----//
        $category_list=Db::name('category')->select();
        $article_recent=Db::name('article')->limit(0,9)->order('publictime','desc')->select();
        $this->assign('article_recent',$article_recent);
        $this->assign('category_list',$category_list);
        $article_hot=Db::name('article')->limit(0,9)->order('pv','desc')->select();
        $this->assign('article_hot',$article_hot);
        $image_list=Db::name('image')->select();
        $this->assign('image_list',$image_list);
        //----公共部分使用end----//
        Db::name('article')->where('id',$id)->update(['pv'=>($data['pv']+1)]);
        return $this->fetch('read');
    }
    function page(){
        $m_id=input('m_id');
        //----分页start----//
        $data['p']=!input('p')?1:input('p');
        $data['limit']=10;
        $data['total']=Db::name('reply')->where('m_id',$m_id)->count();
        $data['page_start']=($data['p']-1)*$data['limit'];
        $data['js_method']='setpage';
        $pagebanner=new AjaxPage($data);
        $reply['banner']=$pagebanner->banner_list();
        //----分页end----//
        //----提取回复开始----//
        $reply['list']=Db::name('reply')->where('m_id',$m_id)->limit($data['page_start'],$data['limit'])->order('time','desc')->select();
        //----提取回复结束----//
        $reply['count']=$data['total'];
        return $reply;
    }
}